package com.xzy.source;

import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;

/**
 * @author xzy.xiao
 * @date 2023/3/15  10:25
 */
@Getter
public class GenericEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {
    private final T data;

    public GenericEvent(Object source, T data) {
        super(source);
        this.data = data;
    }

    /**
     * Return the {@link ResolvableType} describing this instance
     * (or {@code null} if some sort of default should be applied instead).
     */
    @Override
    public ResolvableType getResolvableType() {
        return ResolvableType.forClassWithGenerics(this.getClass(), ResolvableType.forClass(this.data.getClass()));
    }

    @Override
    public String toString() {
        return "From：" + source + " Data：" + data;
    }
}
